package com.anzia.study_4.slice;

import com.anzia.study_4.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Text;
import ohos.bundle.ElementName;

public class MainAbilitySlice extends AbilitySlice {
	@Override
	public void onStart(Intent intent) {
		super.onStart(intent);
		super.setUIContent(ResourceTable.Layout_ability_main);

		Text text = (Text) findComponentById(ResourceTable.Id_text1);
		text.setAutoFontSizeRule(30, 100, 1);
		text.setClickedListener(component -> {
			text.setText(text.getText() + "T");
		});


		Text text1 = (Text) findComponentById(ResourceTable.Id_text2);
		text1.setTruncationMode(Text.TruncationMode.AUTO_SCROLLING);
		text1.startAutoScrolling();

		Button button = (Button) findComponentById(ResourceTable.Id_button1);
		button.setClickedListener(component -> {
			Intent intent1 = new Intent();
			ElementName elementName = new ElementName("", "com.anzia.study_4", "MainAbility_Calculator");
			intent1.setElement(elementName);
			startAbility(intent1);
		});

	}

	@Override
	public void onActive() {
		super.onActive();
	}

	@Override
	public void onForeground(Intent intent) {
		super.onForeground(intent);
	}

	@Override
	protected void onBackground() {
		super.onBackground();
		Text text = (Text) findComponentById(ResourceTable.Id_text1);
		text.setText("T");
	}
}
